package com.shyroke.daydayzhuandao.respository;

import cn.hutool.core.date.DateTime;
import com.shyroke.daydayzhuanapi.entity.NewsEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Repository
public interface NewsRepository extends BaseRepository<NewsEntity,Integer>{
    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query("delete from NewsEntity n where n.date >= ?1 and n.date <= ?2")
    void findByDateBetween(DateTime begin, DateTime end);

    List<NewsEntity> findByIsRead(int isRead);

    List<NewsEntity> findByIsReadAndUserId(Integer isRead, Integer uid);
}
